using System;
using System.Data;
using System.Collections.Generic;
using System.Xml;
using System.Text;

namespace PickGold.Data
{
	/// <summary/>
	public class CTreeTable : CTable
	{
		//
		private STreeTable _ = null;
		/// <summary/>
		public CTreeTable(string name) : base(name) { }
		/// <summary/>
		public CTreeTable(string name, string alias) : base(name, alias) { }
		/// <summary/>
		public CTreeTable(CDatabase db, string name) : base(db, name) { }
		/// <summary/>
		public CTreeTable(CDatabase db, string name, string alias) : base(db, name, alias) { }
		/// <summary/>
		// *****************************************************************************************************
		/// <summary/>
		public CTreeTable(CTable table) : base(GetName(table)) { }
		/// <summary/>
		public CTreeTable(CTable table, string alias) : base(GetName(table), alias) { }
		/// <summary/>
		public CTreeTable(CDatabase db, CTable table) : base(db, GetName(table)) { }
		/// <summary/>
		public CTreeTable(CDatabase db, CTable table, string alias) : base(db, GetName(table), alias) { }

		/// <summary/>
		protected override void SetSchema()
		{
			this.SetSchema(new STreeTable());
		}
		/// <summary/>
		protected void SetSchema(STreeTable s)
		{
			this._ = s;
			base.SetSchema(s);
		}
		//
		private static string GetName(CTable table)
		{
			return "tc" + table.EntityName.Substring(2);
		}

		/// <summary/>
		protected override void PreInitSchema()
		{
			this._DataTable.Columns.Add(Common.C.SuperId, typeof(long)).DefaultValue = this._.SuperID;
			this._DataTable.Columns.Add(Common.C.Id, typeof(long)).DefaultValue = this._.ItemID;
			this._DataTable.Columns.Add(Common.C.Depth, typeof(int)).DefaultValue = this._.ItemDepth;
		}
		//
		#region Property

		/// <summary/>
		public virtual long Super
		{
			set
			{
				this._.SuperID = value;
				this.SetValue(Common.C.SuperId, value);
			}
			get
			{
				return this._.SuperID;
			}
		}

		/// <summary/>
		public virtual long ID
		{
			set
			{
				this._.ItemID = value;
				this.SetValue(Common.C.Id, value);
			}
			get
			{
				return this._.ItemID;
			}
		}

		/// <summary/>
		public virtual int Depth
		{
			set
			{
				this._.ItemDepth = value;
				this.SetValue(Common.C.Depth, value);
			}
			get
			{
				return this._.ItemDepth;
			}
		}
		//
		#endregion
		/// <summary>
		/// --
		/// </summary>
		protected override List<DataColumn> AddKeyColumn()
		{
			List<DataColumn> list = base.AddKeyColumn();
			list.Add(this._DataTable.Columns[Common.C.SuperId]);
			list.Add(this._DataTable.Columns[Common.C.Id]);
			return list;
		}
		/// <summary>
		/// --
		/// </summary>
		/// <param name="position">--</param>
		/// <returns>--</returns>
		public override bool MoveTo(int position)
		{
			if (!base.MoveTo(position))
				return false;

			this._.SuperID = this.GetValue<long>(Common.C.SuperId);
			this._.ItemID = this.GetValue<long>(Common.C.Id);
			this._.ItemDepth = this.GetValue<int>(Common.C.Depth);
			return true;
		}
		//
	}
	//
	public class STreeTable : STable
	{
		//
		public long SuperID = -1;
		public long ItemID = -1;
		public int ItemDepth = 0;
		//
	}
	//
}
//
